package manager.com.ithei.edu.info.manager.service;

import manager.com.ithei.edu.info.manager.dao.BaseTeacherDao;
import manager.com.ithei.edu.info.manager.dao.OtherTeacherDao;
import manager.com.ithei.edu.info.manager.dao.TeacherDao;
import manager.com.ithei.edu.info.manager.domain.Teacher;
import manager.com.ithei.edu.info.manager.factory.StudentFactory;

import java.text.ParseException;

public class TeacherService {
    private static BaseTeacherDao teacherDao = StudentFactory.getTeacherFactory();


    public boolean isExists(String id) {
        boolean flag = false;
        Teacher[] teachers = teacherDao.findAllTeachers();
        for (int i = 0; i < teachers.length; i++) {
            Teacher tea = teachers[i];
            if (tea != null && tea.getSid().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public boolean addTeacher(Teacher stu) throws ParseException {
        return teacherDao.addTeacher(stu);
    }

    public Teacher[] findAllTeachers() {
        Teacher[] teachers = teacherDao.findAllTeachers();
        boolean bl = false;
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i] != null) {
                bl = true;
                break;
            }
        }
        if (bl) {
            return teachers;
        } else {
            return null;
        }
    }

    //删除教师的方法
    public void deleteTeacherByIdTwo(String id) {
        teacherDao.deleteTeacherByIdTwo(id);
    }

    //修改教师的方法
    public void setTeacherByIdTwo(String id, Teacher teachers) {
        teacherDao.setTeacherByIdTwo(id, teachers);
    }
}
